Skip to content

fix: guard against null schedule crashing /tasks page#1567

Open
sweetmantech wants to merge 1 commit intomainfrom
fix/tasks-page-null-schedule-crash-v2
Open

fix: guard against null schedule crashing /tasks page#1567
sweetmantech wants to merge 1 commit intomainfrom
fix/tasks-page-null-schedule-crash-v2

Conversation

@sweetmantech
Copy link
Copy Markdown
Collaborator

@sweetmantech sweetmantech commented Mar 9, 2026

Problem

The /tasks page crashes for some accounts because task.schedule is null/undefined at runtime, even though the DB type declares it as string.

Calling .trim() on null in TaskCard.tsx throws an unhandled exception that crashes the React tree.

Fix

  • TaskCard.tsx: Added null guards around isRecurring(task.schedule) and parseCronToHuman(task.schedule.trim())
  • TaskDetailsDialogContent.tsx: Fallback to empty string when passing schedule prop
  • parseCronToHuman.ts: Early return "No schedule" for falsy input
  • isRecurring.ts: Early return false for falsy input

Defensive checks at both the component and utility level so this class of bug cannot recur.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of tasks without schedules—tasks now properly display "No schedule" instead of undefined or error states, and the Repeat icon only appears when a schedule exists.

Some accounts have scheduled_actions with null/empty schedule values,
causing the /tasks page to crash when calling .trim() or .split() on
null. Added null guards in:
- TaskCard.tsx: guard isRecurring() and parseCronToHuman() calls
- TaskDetailsDialogContent.tsx: fallback to empty string for schedule prop
- parseCronToHuman.ts: early return for falsy input
- isRecurring.ts: early return for falsy input
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-chat Ready Ready Preview Mar 9, 2026 2:57pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

The pull request adds null/undefined safety checks across task scheduling components and utility functions. Guard clauses now prevent errors when task.schedule is absent, with UI components displaying "No schedule" and utility functions returning falsy defaults.

Changes

Cohort / File(s) Summary
UI Components
components/VercelChat/dialogs/tasks/TaskDetailsDialogContent.tsx, components/VercelChat/tools/tasks/TaskCard.tsx
Added conditional rendering and null/undefined guards for schedule information. TaskDetailsDialogContent defaults Schedule prop to empty string; TaskCard conditionally renders Repeat icon and displays "No schedule" when task.schedule is absent.
Utility Functions
lib/tasks/isRecurring.ts, lib/tasks/parseCronToHuman.ts
Added early-return guard clauses for falsy cronExpression inputs. isRecurring returns false; parseCronToHuman returns "No schedule" before attempting parsing logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🛡️ When schedules vanish into the void,
Our guards stand tall, undefined—avoided,
With "No schedule" soft upon the screen,
Safe defaults make the flow serene. ✨

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Solid & Clean Code ✅ Passed PR successfully fixes production crash by adding defensive guards against null/undefined schedule values while maintaining Single Responsibility Principle and improving code safety.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/tasks-page-null-schedule-crash-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/tasks/parseCronToHuman.ts (1)

3-4: Solid defensive guard — consider tightening the type signature.

The early return for falsy input prevents runtime errors and follows the fail-fast principle. However, the function signature declares cronExpression: string while the guard explicitly handles null/undefined. For better developer experience and self-documenting code, consider aligning the type with actual usage:

💡 Optional: Explicit nullable type for clarity
-export const parseCronToHuman = (cronExpression: string): string => {
+export const parseCronToHuman = (cronExpression: string | null | undefined): string => {
   if (!cronExpression) return "No schedule";

This makes the defensive behavior explicit in the contract rather than an implementation detail.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/tasks/parseCronToHuman.ts` around lines 3 - 4, The function
parseCronToHuman currently accepts cronExpression: string but guards against
falsy values; change its parameter type to reflect nullable inputs (e.g.,
cronExpression: string | null | undefined or string | undefined) and update any
related call sites/types if necessary so the contract matches the
implementation; ensure the early-return "No schedule" behavior remains unchanged
and run type checks to catch any callers that need adjustment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/tasks/parseCronToHuman.ts`:
- Around line 3-4: The function parseCronToHuman currently accepts
cronExpression: string but guards against falsy values; change its parameter
type to reflect nullable inputs (e.g., cronExpression: string | null | undefined
or string | undefined) and update any related call sites/types if necessary so
the contract matches the implementation; ensure the early-return "No schedule"
behavior remains unchanged and run type checks to catch any callers that need
adjustment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5dd24320-06bb-4632-a39f-ef3b76abcb0e

📥 Commits

Reviewing files that changed from the base of the PR and between eaeb579 and 8f63454.

📒 Files selected for processing (4)
  • components/VercelChat/dialogs/tasks/TaskDetailsDialogContent.tsx
  • components/VercelChat/tools/tasks/TaskCard.tsx
  • lib/tasks/isRecurring.ts
  • lib/tasks/parseCronToHuman.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant